package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsHomeRecommendSubjectMapper;
import com.mall.model.domain.SmsHomeRecommendSubject;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_home_recommend_subject(首页推荐专题表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsHomeRecommendSubjectApiImpl extends ServiceImpl<SmsHomeRecommendSubjectMapper, SmsHomeRecommendSubject>
        implements SmsHomeRecommendSubjectApi {

    @Autowired
    private SmsHomeRecommendSubjectMapper smsHomeRecommendSubjectMapper;

    @Override
    public Page<SmsHomeRecommendSubject> listPage(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {

        LambdaQueryWrapper<SmsHomeRecommendSubject> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(subjectName), SmsHomeRecommendSubject::getSubjectName, subjectName);
        lqw.eq(recommendStatus != null, SmsHomeRecommendSubject::getRecommendStatus, recommendStatus);
        lqw.orderByDesc(SmsHomeRecommendSubject::getSort);
        Page<SmsHomeRecommendSubject> page = new Page<>(pageNum, pageSize);

        return smsHomeRecommendSubjectMapper.selectPage(page, lqw);
    }

    @Override
    public List<SmsHomeRecommendSubject> findByIds(List<Long> ids, SmsHomeRecommendSubject subject) {

        LambdaQueryWrapper<SmsHomeRecommendSubject> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeRecommendSubject::getId, ids);
        lqw.eq(SmsHomeRecommendSubject::getRecommendStatus, subject.getRecommendStatus());

        return smsHomeRecommendSubjectMapper.selectList(lqw);
    }

    @Override
    public void updateByIds(List<Long> ids, SmsHomeRecommendSubject subject) {

        LambdaQueryWrapper<SmsHomeRecommendSubject> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeRecommendSubject::getId, ids);
        smsHomeRecommendSubjectMapper.update(subject, lqw);
    }

    @Override
    public void updateSort(Integer id, SmsHomeRecommendSubject subject) {

        LambdaQueryWrapper<SmsHomeRecommendSubject> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsHomeRecommendSubject::getId, id);
        smsHomeRecommendSubjectMapper.update(subject, lqw);
    }

}




